<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>高校管理</title>
<meta name="decorator" content="default" />
<%@include file="/WEB-INF/views/include/treetable.jsp"%>
<script type="text/javascript">
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		
		function submitCheck(){
			$("#checkForm").submit();
		}
		$(document).ready(function() {
			var tpl = $("#treeTableTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
			var data = ${fns:toJson(rlist)};
			addRow("#treeTableList", tpl, data, true);
			$("#treeTable").treeTable();
			
			$("#selectAll").change(function() {
				if($("#selectAll").is(':checked')){
					var chboxs = $("input[name='compChecked']")
					for(var i=0;i<chboxs.length;i++){
						chboxs[i].checked = true;
					}
				}else{
					var chboxs = $("input[name='compChecked']")
					for(var i=0;i<chboxs.length;i++){
						chboxs[i].checked = false;
					}
				}
			});
			//给每个添加事件
		});
		function addRow(list, tpl, data, root){
			for (var i=0;i<data.length;i++){
				var row = data[i];
				var childs = row.childList;
				
				var rend = Mustache.render(tpl, {row:row})
				$(list).append(rend);
				
				if(childs){
					for (var j=0;j<childs.length;j++){
						var rend2 = Mustache.render(tpl, {row:childs[j],parentRow:row})
						$(list).append(rend2);
					}
				}
			}
		}
		
		function chkdInput(chkid){
			var ipt =  $("#"+chkid+"")
			var rowid = ipt.attr("rowid");
			var rowpid = ipt.attr("rowpid");
			//处理root节点
			if(rowpid=='0'){
				if(ipt.attr('checked')=='checked'){
					var chboxs = $("input[name='compChecked']")
					for(var i=0;i<chboxs.length;i++){
						chboxs[i].checked = true;
					}
				}else{
					var chboxs = $("input[name='compChecked']")
					for(var i=0;i<chboxs.length;i++){
						chboxs[i].checked = false;
					}
				}
			}else{
				var chboxs = $("input[rowpid='"+rowid+"']")
				if(ipt.attr('checked')=='checked'){
					for(var i=0;i<chboxs.length;i++){
						chboxs[i].checked = true;
					}
				}else{
					for(var i=0;i<chboxs.length;i++){
						chboxs[i].checked = false;
					}
				}
			}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/college/baseCollege">大学列表</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="baseCollege" action="${ctx}/compCollege/comp/search" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}" />
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}" />
		<ul class="ul-form">
			<li><label>学校名称：</label> <form:input path="collegeName" htmlEscape="false" maxlength="255" class="input-medium" /> <input type="hidden" name="companyId" value="${companyId}" /></li>
			<li><label>学校标识码：</label> <form:input path="collegeCode" htmlEscape="false" maxlength="255" class="input-medium" /></li>
			<li><label>所属省：</label> <form:select path="provinceId" class="input-xlarge required">
					<form:options items="${fns:getProvinceList()}" itemLabel="provinceName" itemValue="id" htmlEscape="false" />
				</form:select></li>
			<li><label>分类：</label> 
				<sys:treeselect id="baseCategory" name="categoryId" value="${baseCollege.categoryId}" labelName="baseCollege.categoryName" labelValue="${baseCollege.categoryName}" title="分类" url="/category/baseCategory/treeData?categoryTypeVal=2"
					cssClass="required" allowClear="true" /></li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询" />
				<button class="btn btn-primary" type="button" onclick="javascript:submitCheck()">提交选择</button></li>
			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}" />
	<form:form action="${ctx}/compCollege/comp/save" method="post" id="checkForm" class="breadcrumb form-search">
		<table id="treeTable" class="table table-striped table-bordered table-condensed">
			<thead>
				<tr>
					<th>分类名称</th>
					<th>学校名称</th>
					<th>所属省</th>
					<th>办学层次</th>
					<th>全选<input type="checkbox" value="selectAll" id="selectAll" />
					</th>
			</thead>
			<tbody id="treeTableList">
			</tbody>
		</table>
	</form:form>
	<script type="text/template" id="treeTableTpl">
		<tr id="{{row.categoryId}}" pId="{{row.parentCategoryId}}">
			<td>{{row.categoryName}}</td>
			<td><a href="${ctx}/college/baseCollege/form?opt=detail&id={{row.baseCollege.id}}">{{row.baseCollege.collegeName}}</a></td>
			<td>{{row.baseCollege.provinceName}}</td>
			<td>{{row.baseCollege.level}}</td>
			<td>
				<input type="checkbox" id="{{row.iptId}}chk" onclick="javascript:chkdInput('{{row.iptId}}chk')" name="compChecked" rowid="{{row.categoryId}}" rowpid="{{row.parentCategoryId}}" {{row.checkedStr}} value="{{row.baseCollege.id}}" />
				<input value="{{row.bizCompany.id}}" name="compIds" type="hidden"/>
			</td>
		</tr>
	</script>
</body>
</html>